// Copyright (c) 2009 http://grommet.codeplex.com
// This source is subject to the Microsoft Public License.
// See http://www.opensource.org/licenses/ms-pl.html
// All other rights reserved.

using System;
using Grommet.Ext;

#if MicroFramework
using Microsoft.SPOT;
#endif

namespace Grommet.Net.XBee
{
    public class NodeInfo : Info
    {
        public ushort NetworkAddress { get; private set; }
        public ulong SerialNumber { get; private set; }
        public string Identifier { get; private set; }
        public ushort ParentNetworkAddress { get; private set; }
        public DeviceType DeviceType { get; private set; }
        public byte Status { get; private set; }
        public ushort ProfileID { get; private set; }
        public ushort ManufacturerID { get; private set; }

        public NodeInfo(ulong serialNumber, ushort address, string Identifier)
        {
            this.NetworkAddress = address;
            this.SerialNumber = serialNumber;
            this.Identifier = Identifier;
        }

        public NodeInfo(byte[] data, int startIndex)
        {
            NetworkAddress = BigEndianConvert.ToUInt16(data, startIndex);
            startIndex += 2;
            SerialNumber = BigEndianConvert.ToUInt64(data, startIndex);
            startIndex += 8;
            Identifier = ExtractString(data, startIndex);
            startIndex += Identifier.Length + 1;
            ParentNetworkAddress = BigEndianConvert.ToUInt16(data, startIndex);
            startIndex += 2;
            DeviceType = (DeviceType)data[startIndex];
            startIndex += 1;
            Status = data[startIndex];
            startIndex += 1;
            ProfileID = BigEndianConvert.ToUInt16(data, startIndex);
            startIndex += 2;
            ManufacturerID = BigEndianConvert.ToUInt16(data, startIndex);
        }
    }
}
